package com.dps.omc.mq;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;

/**
 * Created by lip on 2015-12-03.
 */
public class IpQueueDestination extends org.apache.activemq.command.ActiveMQQueue{

    public IpQueueDestination() {
        String IP = "";
        try {
            IP = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        new IpQueueDestination(IP);
    }

    public IpQueueDestination(String ip) {

        this.setPhysicalName(ip);
    }

    public static void main(String[] args) throws SocketException {
        Enumeration netInterfaces= NetworkInterface.getNetworkInterfaces();
        InetAddress   ip   =   null;
        while(netInterfaces.hasMoreElements())
        {
            NetworkInterface   ni=(NetworkInterface)netInterfaces.nextElement();
            System.out.println(ni.getName());
            ip=(InetAddress)   ni.getInetAddresses().nextElement();
            if(   !ip.isSiteLocalAddress()
                    &&   !ip.isLoopbackAddress()
                    &&   ip.getHostAddress().indexOf( ": ")==-1)
            {
                System.out.println( "本机的ip= "   +   ip.getHostAddress());
                break;
            }
            else
            {
                ip=null;
            }
        }
    }
}
